package C040;

/**
 * ClassName: C01
 * Package: C040
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/1 21:52
 * @Version 1.0
 * @Since 1.0
 */
public class C01 {
    public static void main(String[] args) {
        System.out.println(process(new int[8], 0));
    }


    // 数组解决n皇后问题
    // 当前第几行， n皇后的问题
    public static int process(int[] path, int row) {
        if (path.length == row) {
            return 1;
        }

        int res = 0;
        // 判断数据
        for (int i = 0; i < path.length; i++) {
            path[row] = i;
            if (check(path, row)) {
                res += process(path, row + 1);
            }
        }
        return res;
    }

    // 判断当前的位置是否合格
    private static boolean check(int[] path, int i) {
        // 检查行与列的问题
        for (int j = 0; j < i; j++) {
            if(path[j] == path[i] || Math.abs(j - i) == Math.abs(path[i] - path[j])) {
                return false;
            }
        }

        return true;
    }

}
